package com.yx.cloud.activity;

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.yx.cloud.R;
import com.yx.cloud.base.BaseActivity;
import com.yx.cloud.constant.Constants;
import com.yx.cloud.databinding.ServerandprivacyActivityBinding;
import com.yx.cloud.utils.Intent_utils;
import com.yx.cloud.utils.LanguageUtils;
import com.yx.cloud.utils.RomUtils;

public class ServerAndPrivacyActivity extends BaseActivity {
    private final static String TAG = "ServerAndPrivacyActivity";
    String mLanguage;
    String serverUrl, privacyUrl;
    private ServerandprivacyActivityBinding binding;

    @SuppressLint("LongLogTag")
    @Override
    public void onCreate() {
        binding = ServerandprivacyActivityBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        //获取语言类型
        mLanguage = LanguageUtils.getAndsetLanguage(this, "政策");
        initData();
    }

    @SuppressLint("LongLogTag")
    private void initData() {

        String server_privacy = getIntent().getStringExtra("Server_Privacy");
        if ("Server".equals(server_privacy)) {
            binding.tvServerAndPriacyTitle.setText(getString(R.string.MY_ServiceAgreement));
        } else {
            binding.tvServerAndPriacyTitle.setText(getString(R.string.MY_PrivacyPolicy));
        }

        binding.webview.setVerticalScrollBarEnabled(false); //不显示垂直滚动条
        binding.webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }
        });
        if (mLanguage.equals(Constants.ZH)) {
            //中文
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement.html";//"http://info.inxni.com/PolicyAgreement/UserAgreement.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy.html";
        } else if (mLanguage.equals(Constants.EN)) {
            //英文
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_en.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_en.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_en.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_en.html";
        } else if (mLanguage.equals(Constants.DE)) {
            //德语
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_German.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_German.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_German.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_German.html";
        } else if (mLanguage.equals(Constants.ES)) {
            //西班牙
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_Spanish.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_Spanish.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_Spanish.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_Spanish.html";
        } else if (mLanguage.equals(Constants.FR)) {
            //法语
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_French.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_French.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_French.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_French.html";
        } else if (mLanguage.equals(Constants.IT)) {
            //意大利语
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_Italian.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_Italian.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_Italian.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_Italian.html";
        } else if (mLanguage.equals(Constants.JA)) {
            //日语
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_Japanese.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_Japanese.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_Japanese.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_Japanese.html";
        } else if (mLanguage.equals(Constants.PL)) {
            //波兰语
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_Polish.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_Polish.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_Polish.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_Polish.html";
        } else if (mLanguage.equals(Constants.PT)) {
            //葡萄牙语
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_Portuguese.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_Portuguese.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_Portuguese.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_Portuguese.html";
        } else if (mLanguage.equals(Constants.RU)) {
            //俄语
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_Russian.html";//http://info.inxni.com/PolicyAgreement/UserAgreement_Russian.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_Russian.html";//http://info.inxni.com/PolicyAgreement/PrivacyPolicy_Russian.html";
        } else if (mLanguage.equals(Constants.KO)) {
            //韩语
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_Korean.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_Korean.html";
        } else {
            serverUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/UserAgreement_en.html";
            privacyUrl = "http://info.inxni.com/PolicyAgreement/INXNIhome/PrivacyPolicy_en.html";
        }
        setServerPrivacy(server_privacy, serverUrl, privacyUrl);

        binding.ivServerAndPriacyReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RomUtils.isFastClick()) {
                    return;
                }
                Intent_utils.backIntent(ServerAndPrivacyActivity.this);
            }
        });

    }

    private void setServerPrivacy(String isServerPrivacy, String serverUrl, String privacyUrl) {
        if ("Server".equals(isServerPrivacy)) {
            binding.webview.loadUrl(serverUrl);
        } else {
            binding.webview.loadUrl(privacyUrl);
        }
    }

}
